<?php
class Model_Game extends Model {
	public  $table="game";
	public	$cat="game_category";
	
	
	//======= Add new user==============	
		public function add_game($data)
		{
			return $this->insert($this->table,$data);
			
		}
	//====Update user infor
		public function update_game($data,$where)
		{
			$this->where($where);
			return $this->update($this->table,$data);
		}
		//====Get game
		public function get_game($id)
		{
			$this->where="id = $id";
			return $this->getdata($this->table);
		}
		//=====Login
		public function delete_game($id)
		{
			$this->where="id='$id'";
			return $this->delete($this->table);
			//delete comment=======
			
				
		}
		//======Get home game
		public function get_home_game(){
		$this->where=" home=1";
		$this->limit="0,1";
		$this->getdata($this->table);
		return $this->fetchOne();
		}
		//=======GET LATEST  game
		public function get_latest_game(){
		$sql="select game.id,game.tieude,game.seo_tieude,game.hinhanh,game.user_add,game.time_show,game.gioithieu,cat.cat_alias,cat.cat_id,cat.cat_title from game left join game_category as cat on game.category=cat.cat_id order by home desc,capnhat_time desc limit 0,10";
		$this->query($sql);		
		return $this->fetchAll();
		}
		public function check_game_user($id,$user)
		{	
			$wh=array("user_add="=>$user,
					  "id="		 =>$id);
			$this->where($wh);
			$this->getdata($this->table);
			if($this->num_rows()==1){
			return true;
			}
			else{
			return false;
			}
			
				
		}
		
	//====Get Category
		public function get_cat()
		{	$this->order="thutu asc";
			$this->getdata($this->cat);
		}

	//======Get Cat by id
		public function get_catbyid($id)
		{	$this->where="cat_id=$id";
			
			$this->getdata($this->cat);
		}

	
	
	
}
